#include <stdio.h>
#include <stdlib.h>
/*
 * 命名习惯 struct 命名时加上后缀_st
 * 	    union 命名时加上后缀_un
 * */
#define NAMESIZE 32
struct simp_st
{
	int i;
	char ch1;
	float f;
	char ch;
}__attribute__((packed));

struct birthday_st
{
	int year;
	int month;
	int day;


};

struct student_st
{
	int id;
	char name[NAMESIZE];
//	int year,month,day;
	struct birthday_st birth;
	
/*	struct birthday_st
	{
		int year;
		int month;
		int day;
	}birth;	
*/
	int math;
	int chinese;



};


//开销：12字节
void print_st_size(struct simp_st b)
{
	printf("[%s]",__FUNCTION__);
	printf("sizeof(struct):%d\n",sizeof(b));
}


//开销：8字节
void print_st_size_by_point(struct simp_st *p)
{

	printf("[%s]",__FUNCTION__);
	printf("sizeof(struct):%d\n",sizeof(p));
//	调用结构体成员变量记得用 ->
	
}







int main(void)
{
#if 0 
/*
	struct simp_st a = {123,456.789,'a'};

	printf("%d	%f	%c\n",a.i,a.f,a.ch);
*/

	int i = 0;	
	struct student_st stu = {10011,"Alan",{2014,11,11},98,97};
	struct student_st *p = &stu;

	struct student_st arr[2] = {{10011,"Alan",{2014,11,11},98,97},{10012,"John",{2012,12,12},90,80}};
//	p= &arr[0];
	p = arr + 0;

//	stu={.math= 100};

	printf("%d	%s	%d	%d	%d	%d	%d\n",stu.id,stu.name,stu.birth.year,stu.birth.month,stu.birth.day,stu.math,stu.chinese);

	printf("%d	%s	%d	%d	%d	%d	%d\n",p->id,p->name,p->birth.year,p->birth.month,p->birth.day,p->math,p->chinese);

	for (i=0;i<2;i++,p++) //p = p + 1
	{
		printf("%d	%s	%d	%d	%d	%d	%d\n",p->id,p->name,p->birth.year,p->birth.month,p->birth.day,p->math,p->chinese);
	}
#else

	struct simp_st a;
	struct simp_st *p = &a;
 
	printf("sizeof(struct):%d\n",sizeof(a));
/* sizeof 计算结构体地址对齐完成后占用的空间大小  
 * 
 * 不同的机器 不同的编译器对结构体地址对齐处理略有差异
 * 让编译器不进行结构体地址对齐（网络传输）：在定义时加上
 *__attribute__((packed)) 宏
*/
	printf("sizeof(point):%d\n",sizeof(p));

	print_st_size(a);
//	print_st_size_by_point(p);   
	print_st_size_by_point(&a);


#endif
	exit(0);

}
